package com.qianli.user.facade.query.impl.behavior;

import com.fqgj.common.api.Response;
import com.qianli.user.application.UserBehaviorApplication;
import com.qianli.user.facade.query.behavior.UserBehaviorQueryServiceFacade;
import com.qianli.user.ro.UserStateCode;
import com.qianli.user.ro.behavior.*;
import com.qianli.user.ro.query.UserBaseQueryRO;
import com.qianli.user.ro.query.UserLoginQueryRO;
import com.qianli.user.service.UserBehaviorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * name:行为信息
 * auth:ting.li@qianli-inc.com
 * date:2018/1/9 11:22
 * version: v1.0.0
 **/
@Service("userBehaviorQueryServiceFacade")
public class UserBehaviorQueryServiceFacadeImpl implements UserBehaviorQueryServiceFacade{

    private static final Logger LOGGER = LoggerFactory.getLogger(UserBehaviorQueryServiceFacade.class);

    @Autowired
    private UserBehaviorApplication userBehaviorApplication;
    @Autowired
    private UserBehaviorService userBehaviorService;

    /**
     * 查询设备信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorDeviceRO> queryUserLatestBehaviorDevice(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDevice param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDevice param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDevice param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorInfoRO behaviorInfoRO = userBehaviorApplication.load(queryRO.getUserCode());
        return Response.ok(behaviorInfoRO.getUserBehaviorDevice());
    }

    /**
     * 查询用户指定设备信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorDeviceRO> getUserBehaviorDeviceByUserCodeAndGuestId(UserBehaviorDeviceRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorDeviceByUserCodeAndGuestId param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorDeviceByUserCodeAndGuestId param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorDeviceByUserCodeAndGuestId param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        if(null == queryRO.getGuestId()){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorDeviceByUserCodeAndGuestId param guestId can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"guestId can not be null");
        }
        UserBehaviorDeviceRO userBehaviorDevice = userBehaviorService.getUserBehaviorDeviceByUserCodeAndGuestId(queryRO);
        return Response.ok(userBehaviorDevice);
    }

    /**
     * 数美
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorDeviceShumeiRO> queryUserLatestBehaviorDeviceShumei(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDeviceShumei param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDeviceShumei param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorDeviceShumei param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorInfoRO behaviorInfoRO = userBehaviorApplication.load(queryRO.getUserCode());
        return Response.ok(behaviorInfoRO.getUserBehaviorDeviceShumei());
    }

    /**
     * 查询gps
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorGpsRO> queryUserLatestBehaviorGps(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorGps param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorGps param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorGps param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorInfoRO behaviorInfoRO = userBehaviorApplication.load(queryRO.getUserCode());
        return Response.ok(behaviorInfoRO.getUserBehaviorGps());
    }

    /**
     * 登录信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorLoginRO> queryUserLatestBehaviorLogin(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorLoginRO loginRO = userBehaviorApplication.queryUserLatestBehaviorLogin(queryRO.getUserCode());
        return Response.ok(loginRO);
    }

    /**
     * 根据id查询登录信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorLoginRO> queryUserBehaviroLoginById(UserLoginQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorLogin param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }

        return null;
    }

    /**
     * 注册信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorRegisterRO> getUserBehaviorRegister(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorRegister param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorRegister param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.getUserBehaviorRegister param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorRegisterRO registerRO = userBehaviorApplication.getUserBehaviorRegister(queryRO.getUserCode());
        return Response.ok(registerRO);
    }

    /**
     * wifi信息
     * @param queryRO
     * @return
     */
    @Override
    public Response<UserBehaviorWifiRO> queryUserLatestBehaviorWifi(UserBaseQueryRO queryRO) {
        if(null == queryRO){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorWifi param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK);
        }
        if(null == queryRO.getAppCode()||null == queryRO.getBiz()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorWifi param appCode and biz can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"appCode and biz can not be null");
        }
        if(null == queryRO.getUserCode()){
            LOGGER.info("UserBehaviorQueryServiceFacade.queryUserLatestBehaviorWifi param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"userCode can not be null");
        }
        UserBehaviorInfoRO behaviorInfoRO = userBehaviorApplication.load(queryRO.getUserCode());
        return Response.ok(behaviorInfoRO.getUserBehaviorWifi());
    }
}
